package Io;

import java.io.*;

public class Test8 {
    //缓冲字符流
    public static void main(String[] args) {
//     Test8.testBufferedReader("D:\\aa\\a\\tt1.txt");
//        Test8.testBufferedWrite("D:\\aa\\a\\tt1.txt");
        Test8.copyFile("D:\\aa\\a\\b\\tt1.txt","D:\\aa\\a\\b\\tt4.txt");
    }

    public static void testBufferedReader(String inpath) {
        try {
            FileReader fr = new FileReader(inpath);
            BufferedReader br = new BufferedReader(fr);
            char[] c = new char[100];
            int len = 0;
            while ((len = br.read(c)) != -1) {
                System.out.println(new String(c, 0, len));
            }
            br.close();
            fr.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void testBufferedWrite(String outpath) {
        try {
            FileWriter fw = new FileWriter(outpath);
            BufferedWriter bw = new BufferedWriter(fw);
            String str = "12345678";
            bw.write(str);
            bw.flush();
            bw.close();
            fw.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void copyFile(String inpath,String outpath){
        try {
            BufferedReader br = new BufferedReader(new FileReader(inpath));
            BufferedWriter bw=new BufferedWriter(new FileWriter(outpath));
            char [] c=new char[100];
            int len=0;
            while ((len=br.read(c))!=-1){
                bw.write(c,0,len);
            }
            bw.flush();
            bw.close();
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}